<template>
	<view class="fui-wrap">
		<block v-if="!notice.subscribe">
			<fui-notice-bar :padding="['20rpx','20rpx','20rpx','0rpx']" background="#f4d492" :content="`您还没有关注【${notice.mpappname}】公众号，获取通知消息必须先关注公众号，再下拉刷新页面！`" size="28">
				<view class="fui-icon__box">
					<fui-icon name="notice-fill" :size="40" color="#ea3030"></fui-icon>
				</view>
			</fui-notice-bar>
			<official-account></official-account>
		</block>
		<fui-list>
			<fui-list-cell :highlight="false" :padding="['22rpx', '32rpx', '8rpx', '0rpx']">
				<fui-panel :isBorder="false" :panelData="{title: '车辆出入通知',desc:'您认证的车辆出入云起停车平台合作的停车场时，会通过微信发通知给您。'}"></fui-panel>
				<view style="width: 170rpx;">
					<fui-switch v-if="init" @change="change" name="records" :checked="notice.subscribe && notice.records?true:false"></fui-switch>
				</view>
			</fui-list-cell>
			<fui-list-cell :highlight="false" :padding="['22rpx', '32rpx', '8rpx', '0rpx']">
				<fui-panel :isBorder="false" :panelData="{title: '月租到期通知',desc:'与您相关的月租车辆快到期时，会通过微信提前发通知到您。'}"></fui-panel>
				<view style="width: 170rpx;">
					<fui-switch v-if="init" @change="change" name="monthly" :checked="notice.subscribe && notice.monthly?true:false"></fui-switch>
				</view>
			</fui-list-cell>
			<fui-list-cell :highlight="false" :padding="['22rpx', '32rpx', '8rpx', '0rpx']">
				<fui-panel :isBorder="false" :panelData="{title: '余额不足通知',desc:'与您相关的储值车辆余额不足时，会通过微信提前发通知到您。。'}"></fui-panel>
				<view style="width: 170rpx;">
					<fui-switch v-if="init" @change="change" name="stored" :checked="notice.subscribe && notice.stored?true:false"></fui-switch>
				</view>
			</fui-list-cell>
			<fui-list-cell :highlight="false" :padding="['22rpx', '32rpx', '8rpx', '0rpx']">
				<fui-panel :isBorder="false" :panelData="{title: '发票开取通知',desc:'您申请开取发票后，当停车场为您完成开取发票后会发通知到您。'}"></fui-panel>
				<view style="width: 170rpx;">
					<fui-switch v-if="init" @change="change" name="invoice" :checked="notice.subscribe && notice.invoice?true:false"></fui-switch>
				</view>
			</fui-list-cell>
			<fui-list-cell :highlight="false" :padding="['22rpx', '32rpx', '8rpx', '0rpx']">
				<fui-panel :isBorder="false" :panelData="{title: '优惠券过期通知',desc:'与您相关的停车优惠券快到期时，会通过微信发通知到您。'}"></fui-panel>
				<view style="width: 170rpx;">
					<fui-switch v-if="init" @change="change" name="coupon" :checked="notice.subscribe && notice.coupon?true:false"></fui-switch>
				</view>
			</fui-list-cell>
		</fui-list>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				init:false,
				notice:''
			}
		},
		onShow() {
			this.getInfo();
		},
		onPullDownRefresh() {
			this.getInfo(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			getInfo:function(callback){
				this.$get('index/notice').then(res=>{
					this.notice=res;
					this.init=true;
					if(callback){
						callback();
					}
				});
			},
			change:function(e){
				let name=e.name;
				let value=e.detail.value;
				if(!this.notice.subscribe){
					this.$msg('请先关注公众号')
					this.init=false;
					setTimeout(()=>{
						this.init=true;
					},200);
					return;
				}
				this.$post('index/notice',{value:value?1:0,name:name},true,true);
			}
		}
	}
</script>

<style lang="scss" scoped>
.fui-wrap{
	background-color: #fff;
}
.fui-icon__box{
	padding:0 20rpx;
}
</style>